package com.lin.fengxiu.dto.validators;

import com.lin.fengxiu.dto.PersonDTO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @ClassName PasswordValidator
 * @Description TODO
 * @Author wushaopei
 * @Date 2021/3/7 21:54
 * @Version 1.0
 */
public class PasswordValidator implements ConstraintValidator<PasswordEqual,PersonDTO> {

    private int min;
    private int max;

    @Override
    public void initialize(PasswordEqual constraintAnnotation) {
        this.min = constraintAnnotation.min();
        this.max = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(PersonDTO personDTO, ConstraintValidatorContext constraintValidatorContext) {
        String password1 = personDTO.getPassword1();
        String password2 = personDTO.getPassword2();
        boolean match = password1.equals(password2);

        return match;
    }

    //  第二个：自定义注解修饰的目标的类型

}
